/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dusin.adserver.utils;

/**
 *
 * @author dusin
 */
public class SqlUtils {
    
    //拼接where 的 in 条件,类型为字符串，如果为空则返回空字符串
    public static String join(String field,String[] values ){
        StringBuilder sb = new StringBuilder();
        if(values==null||field==null||values.length==0){
            return "";
        }else{
            sb.append(" and ").append(field).append(" in ");
            sb.append("(");
            boolean isFirst=true;
            for(String v:values){
                if(isFirst){ //第一个参数前面不需要有逗号
                    sb.append("'").append(v).append("'");
                    isFirst=false;
                }else{  //第二个参数起，前面需要一个逗号
                    sb.append(",'").append(v).append("'");
                }
            }
            sb.append(") ");
        }
        return sb.toString();
    }
}
